﻿// Decompiled with JetBrains decompiler
// Type: MCM.Abstractions.ServiceCollectionExtensions
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using BUTR.DependencyInjection;
using MCM.Abstractions.FluentBuilder;
using MCM.Abstractions.Global;
using MCM.Abstractions.PerCampaign;
using MCM.Abstractions.PerSave;
using MCM.Abstractions.Properties;
using System;

#nullable enable
namespace MCM.Abstractions
{
  public static class ServiceCollectionExtensions
  {
    public static IGenericServiceContainer AddSettingsProvider<TService, TImplementation>(
      this IGenericServiceContainer services)
      where TService : BaseSettingsProvider
      where TImplementation : class, TService
    {
      services.RegisterSingleton<TImplementation>();
      services.RegisterSingleton<TService>((Func<IGenericServiceFactory, TService>) (sp => (TService) sp.GetService<TImplementation>()));
      services.AddSettingsProvider<TImplementation>();
      return services;
    }

    public static IGenericServiceContainer AddSettingsProvider<TImplementation>(
      this IGenericServiceContainer services)
      where TImplementation : BaseSettingsProvider
    {
      services.RegisterSingleton<TImplementation>();
      services.RegisterSingleton<BaseSettingsProvider>((Func<IGenericServiceFactory, BaseSettingsProvider>) (sp => (BaseSettingsProvider) sp.GetService<TImplementation>()));
      return services;
    }

    public static IGenericServiceContainer AddSettingsFormat<TService, TImplementation>(
      this IGenericServiceContainer services)
      where TService : class, ISettingsFormat
      where TImplementation : class, TService
    {
      services.RegisterSingleton<TImplementation>();
      services.RegisterSingleton<TService>((Func<IGenericServiceFactory, TService>) (sp => (TService) sp.GetService<TImplementation>()));
      services.AddSettingsFormat<TImplementation>();
      return services;
    }

    public static IGenericServiceContainer AddSettingsFormat<TImplementation>(
      this IGenericServiceContainer services)
      where TImplementation : class, ISettingsFormat
    {
      services.RegisterSingleton<TImplementation>();
      services.RegisterSingleton<ISettingsFormat>((Func<IGenericServiceFactory, ISettingsFormat>) (sp => (ISettingsFormat) sp.GetService<TImplementation>()));
      return services;
    }

    public static IGenericServiceContainer AddSettingsPropertyDiscoverer<TService, TImplementation>(
      this IGenericServiceContainer services)
      where TService : class, ISettingsPropertyDiscoverer
      where TImplementation : class, TService
    {
      services.RegisterSingleton<TImplementation>();
      services.RegisterSingleton<TService>((Func<IGenericServiceFactory, TService>) (sp => (TService) sp.GetService<TImplementation>()));
      services.AddSettingsPropertyDiscoverer<TImplementation>();
      return services;
    }

    public static IGenericServiceContainer AddSettingsPropertyDiscoverer<TImplementation>(
      this IGenericServiceContainer services)
      where TImplementation : class, ISettingsPropertyDiscoverer
    {
      services.RegisterSingleton<TImplementation>();
      services.RegisterSingleton<ISettingsPropertyDiscoverer>((Func<IGenericServiceFactory, ISettingsPropertyDiscoverer>) (sp => (ISettingsPropertyDiscoverer) sp.GetService<TImplementation>()));
      return services;
    }

    public static IGenericServiceContainer AddSettingsContainer<TService, TImplementation>(
      this IGenericServiceContainer services)
      where TService : class, ISettingsContainer
      where TImplementation : class, TService
    {
      services.RegisterSingleton<TImplementation>();
      services.RegisterSingleton<TService>((Func<IGenericServiceFactory, TService>) (sp => (TService) sp.GetService<TImplementation>()));
      services.AddSettingsContainer<TImplementation>();
      return services;
    }

    public static IGenericServiceContainer AddSettingsContainer<TImplementation>(
      this IGenericServiceContainer services)
      where TImplementation : class, ISettingsContainer
    {
      services.RegisterSingleton<TImplementation>();
      services.RegisterSingleton<ISettingsContainer>((Func<IGenericServiceFactory, ISettingsContainer>) (sp => (ISettingsContainer) sp.GetService<TImplementation>()));
      if (typeof (IPerCampaignSettingsContainer).IsAssignableFrom(typeof (TImplementation)))
        services.RegisterSingleton<IPerCampaignSettingsContainer>((Func<IGenericServiceFactory, IPerCampaignSettingsContainer>) (sp => (IPerCampaignSettingsContainer) (object) sp.GetService<TImplementation>()));
      if (typeof (IPerSaveSettingsContainer).IsAssignableFrom(typeof (TImplementation)))
        services.RegisterSingleton<IPerSaveSettingsContainer>((Func<IGenericServiceFactory, IPerSaveSettingsContainer>) (sp => (IPerSaveSettingsContainer) (object) sp.GetService<TImplementation>()));
      if (typeof (IGlobalSettingsContainer).IsAssignableFrom(typeof (TImplementation)))
        services.RegisterSingleton<IGlobalSettingsContainer>((Func<IGenericServiceFactory, IGlobalSettingsContainer>) (sp => (IGlobalSettingsContainer) (object) sp.GetService<TImplementation>()));
      if (typeof (IFluentPerCampaignSettingsContainer).IsAssignableFrom(typeof (TImplementation)))
        services.RegisterSingleton<IFluentPerCampaignSettingsContainer>((Func<IGenericServiceFactory, IFluentPerCampaignSettingsContainer>) (sp => (IFluentPerCampaignSettingsContainer) (object) sp.GetService<TImplementation>()));
      if (typeof (IFluentPerSaveSettingsContainer).IsAssignableFrom(typeof (TImplementation)))
        services.RegisterSingleton<IFluentPerSaveSettingsContainer>((Func<IGenericServiceFactory, IFluentPerSaveSettingsContainer>) (sp => (IFluentPerSaveSettingsContainer) (object) sp.GetService<TImplementation>()));
      if (typeof (IFluentGlobalSettingsContainer).IsAssignableFrom(typeof (TImplementation)))
        services.RegisterSingleton<IFluentGlobalSettingsContainer>((Func<IGenericServiceFactory, IFluentGlobalSettingsContainer>) (sp => (IFluentGlobalSettingsContainer) (object) sp.GetService<TImplementation>()));
      return services;
    }

    public static IGenericServiceContainer AddExternalSettingsProvider<TImplementation>(
      this IGenericServiceContainer services)
      where TImplementation : class, IExternalSettingsProvider
    {
      services.RegisterSingleton<TImplementation>();
      services.RegisterSingleton<IExternalSettingsProvider>((Func<IGenericServiceFactory, IExternalSettingsProvider>) (sp => (IExternalSettingsProvider) sp.GetService<TImplementation>()));
      return services;
    }

    public static IGenericServiceContainer AddSettingsBuilderFactory<TImplementation>(
      this IGenericServiceContainer services)
      where TImplementation : class, ISettingsBuilderFactory
    {
      services.RegisterSingleton<TImplementation>();
      services.RegisterSingleton<ISettingsBuilderFactory>((Func<IGenericServiceFactory, ISettingsBuilderFactory>) (factory => (ISettingsBuilderFactory) factory.GetService<TImplementation>()));
      return services;
    }
  }
}
